package cn.yinyu.queue.module.ecg.api.doctor;

import cn.yinyu.queue.framework.common.exception.ErrorCode;
import cn.yinyu.queue.framework.common.exception.enums.GlobalErrorCodeConstants;
import cn.yinyu.queue.module.ecg.dal.dataobject.room.RoomDO;
import cn.yinyu.queue.module.ecg.service.queue.QueueService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class DoctorApiImpl implements DoctorApi {

    @Resource
    private QueueService queueService;

    @Override
    public ErrorCode bedDoctorOff(Long userId, String userName) {
        List<RoomDO> roomDOList = queueService.getDocRoomInfo(userId);
        // 未入座, 跳过
        if (roomDOList.isEmpty()) {
            return GlobalErrorCodeConstants.SUCCESS;
        }

        roomDOList.forEach( bedItem -> queueService.startBedDoctorOff(bedItem.getRoomId(), bedItem.getBedNo(), userId, userName));
        return GlobalErrorCodeConstants.SUCCESS;
    }

}

